<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../../../inc/conn.asp"-->
<!--#include file="../common/u.asp"-->
<%links="personal"%>
<%
id=request.QueryString("edit")
if id<>"" then
  set rss=conn.execute("select * from address where uid='"&uid&"' and id="&id&"")
  if not rss.eof then
	codezip=rss("codezip")
	Location=rss("Location")
	name=rss("name")
	mobile=rss("mobile")
	strtel=rss("tel")
	flag=rss("flag")
  set rss=nothing
  end if
  
  if strtel<>"" then
    strtel=split(strtel,"-")
	for i=0 to ubound(strtel)
	  if i=0 then tel=strtel(i)
	  if i=1 then tel2=strtel(i)
	  if i=2 then tel3=strtel(i)
	next
  end if
  
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>个人资料</title>
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<link rel="stylesheet" type="text/css" href="/css/style.css" />
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.tabs.js"></script>
<script language="javascript" type="text/javascript" src="/js/pd.js"></script>
<script>
function myjobchk(){
if (document.formcn.codezip.value=="")
{alert("邮政编码不能为空");
document.formcn.codezip.focus();
return false;
}
if(!Checkshuzi(formcn.codezip.value)){
alert("邮政编码输入错误");
formcn.codezip.focus();
return false;
}
if(formcn.codezip.value.length>8 || formcn.codezip.value.length<4){
alert("邮政编码输入错误")
formcn.codezip.focus()
return(false)
}
if (document.formcn.Location.value=="")
{alert("地址不能为空");
document.formcn.Location.focus();
return false;
}  
if(formcn.Location.value.length>50 || formcn.Location.value.length<10){
alert("请输入完整地址：xx省xx市xx区/县xx号，50字符以内")
formcn.Location.focus()
return(false)
}
if (document.formcn.name.value=="")
{alert("收件人不能为空");
document.formcn.name.focus();
return false;
}  
if(formcn.name.value.length>15 || formcn.name.value.length<2){
alert("收件人输入错误")
formcn.name.focus()
return(false)
}

if (document.formcn.mobile.value!="")
{

    if(!Checkshuzi(formcn.mobile.value)){
	alert("手机号码输入错误");
	formcn.mobile.focus();
	return false;
	}
	if(formcn.mobile.value.length!=11){
	alert("手机号码输入错误");
	formcn.mobile.focus();
	return false;
	}
}


if (document.formcn.mobile.value=="")
{
	if (document.formcn.tel.value=="")
	{alert("手机或电话不能同时为空");
	document.formcn.tel.focus();
	return false;
	}  
	if(!Checkshuzi(formcn.tel.value)){
	alert("电话区号输入错误");
	formcn.tel.focus();
	return false;
	}
	if(formcn.tel.value.length>4 || formcn.tel.value.length<2){
	alert("电话区号输入错误")
	formcn.tel.focus()
	return(false)
	}
	if (document.formcn.tel2.value=="")
	{alert("电话中间部分不能为空");
	document.formcn.tel2.focus();
	return false;
	} 
	if(!Checkshuzi(formcn.tel2.value)){
	alert("电话中间部分输入错误");
	formcn.tel2.focus();
	return false;
	}
	if(formcn.tel2.value.length>10 || formcn.tel2.value.length<6){
	alert("电话中间部分输入错误")
	formcn.tel2.focus()
	return(false)
	}
}    
return(true);
}
</script>
</head>
<body>

<!--#include file="../../common/top.asp"-->




<div class="fullwidth">
	<div class="place ">
		<a href="/">首页</a> &gt; <a href="/user">会员中心</a> &gt; 个人资料
	</div>
</div>
<!--main-->
<div class="fullwidth bg1">
	<div class="main">
		
		
        
        
        <!--#include file="../common/left.asp"-->
        
        
		
		<div class="right_show f_r">
			
			<div class="title_4">
				<h2>个人资料</h2><div></div>
			</div>
			<div class="reg_box reg_s_1 account order_tab order_tab_3">
				<ul class="tab_menu">
					<li><a href="/user/personal">基本资料</a></li>
					<li class="current">地址管理</li>
				</ul>
				<div class="tab_box">
					
					<div>
						<p class="tip tip_3">最多可以保存5个收货地址。</p>
						<div class="clear20"></div>
						<div class="title_11"><h2>新增地址</h2></div>
						<div class="clear20"></div>
						<div class="new_address new_address_1">
							<form name="formcn" method="post" action="" onSubmit="return myjobchk();">
								<dl>
									<dd><span>邮政编码：<font class="red">*</font></span><input type="text" name="codezip" class="text" value="<%=codezip%>" /></dd>
									<dd><span>地址：<font class="red">*</font></span><textarea class="textar_2" name="Location"><%=Location%></textarea></dd>
									<dd><span>收货人姓名：<font class="red">*</font></span><input type="text" name="name" value="<%=name%>" class="text" placeholder="长度不超过25个字" /></dd>
									<dd><span>手机号码：</span><input type="text" class="text" name="mobile" value="<%=mobile%>" placeholder="手机和电话请至少填写一个" /></dd>
									<dd><span>电话号码：</span><input type="text" name="tel" value="<%=tel%>" class="text text_2" placeholder="区号" /> - <input type="text" name="tel2" value="<%=tel2%>" class="text text_2" placeholder="电话" /> - <input type="text" name="tel3" value="<%=tel3%>" class="text text_2" placeholder="分机" /></dd>
									<dd><span>设置默认：</span><input type="checkbox" name="flag" value="1"<%if flag=true then response.Write " checked"%>/> 设置为默认地址 <font class="fgray">设置后系统将在购买时自动选中该收货地址</font></dd>
									<dd><span></span>
										<input type="submit" class="btn_16 ml100" value="保存" />
                                        <input type="hidden" name="t" value="yes" />
									</dd>
								</dl>
							</form>
						</div>
						<div class="title_11"><h2>已保存的地址</h2></div>
						<div class="clear20"></div>
						<table class="stable stable_1 stable_2 stable_4 width9">
							<tr>
								<th>收货人</th>
								<th>地址</th>
								<th>邮编</th>
								<th>电话</th>
								<th>操作</th>
							</tr>
							
                            
                            
                            <%
							'地址			
							set rsbanner=server.CreateObject("adodb.recordset")
							sql="select * from address where uid='"&uid&"' order by id asc"
							rsbanner.open sql,conn,1,3
							if not rsbanner.eof then
							do while not rsbanner.eof 
							%>
                            <tr>
								<td><%=rsbanner("name")%></td>
								<td><%=rsbanner("Location")%></td>
								<td><%=rsbanner("codezip")%></td>
								<td><%=rsbanner("tel") &" &nbsp; "& rsbanner("mobile")%></td>
								<td><a href="?del=<%=rsbanner("id")%>" class="blue">删除</a> | <a href="?edit=<%=rsbanner("id")%>" class="blue">修改</a> </td>
							</tr>
                            <%
							rsbanner.movenext
							loop
							rsbanner.close
							set rsbanner=nothing
							end if		 
							%>
							
						</table>
						<div class="clear20"></div>
					</div>				
					
				</div>
				<div class="clear20"></div>
				<div class="clear20"></div>
			</div>	
			
		</div>
		
		
	</div>
</div>

<div class="clear"></div>




<!--#include file="../../common/footer.asp"-->



</body>
</html>
<%
if request("del")<>"" then
conn.execute("delete from address where uid='"&uid&"' and id="&request.QueryString("del")&"")
response.write"<script language=JavaScript>{window.alert('删除成功');window.location.href='/user/address';}</script>"
end if



if request.Form("t")="yes" then
    codezip=request.Form("codezip")
	Location=request.Form("Location")
	name=request.Form("name")
	mobile=request.Form("mobile")
	tel=request.Form("tel")
	tel2=request.Form("tel2")
	tel3=request.Form("tel3")
	Flag=request.Form("Flag")
	if Flag="" then Flag=0
	
	if codezip="" or Location="" or name="" then
	response.write"<script>alert('邮编、地址、收件人、电话或手机不能为空');</script>"
	response.write"<script>window.history.back(-1);</script>"
	response.end
	end if
	
	set rsx=server.createobject("adodb.recordset")
	if id="" then
	  sql="select * from address"
	  rsx.open sql,conn,1,3
	  rsx.addnew
	else
	  sql="select * from address where uid='"&uid&"' and id="&id&""
	  rsx.open sql,conn,1,3
	end if
	rsx("uid")=uid
	rsx("codezip")=codezip
	rsx("Location")=Location
	rsx("name")=name
	rsx("mobile")=mobile
	if tel2<>"" then rsx("tel")=tel&"-"&tel2&"-"&tel3
	rsx("Flag")=Flag
	rsx.update
	rsx.close
	set rsx=nothing 
	response.write"<script language=JavaScript>{window.alert('保存成功');window.location.href='/user/address';}</script>"
end if
%>